<template>
    <!-- 修改资料 -->

    <div>
        <el-form label-width="85px" :model="form" label-position="right" ref="formRef" :rules="formRules">
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="任务名称" prop="jobName">
                        <el-input v-model="form.jobName"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="小组名称" prop="jobGroup">
                        <el-input v-model="form.jobGroup"></el-input>
                    </el-form-item></el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="cron表达式" prop="cronExpression">
                        <el-input v-model="form.cronExpression"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">

                    <el-form-item label="服务名称">
                        <el-input v-model="form.springId"></el-input>
                    </el-form-item></el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="方法名">
                        <el-input v-model="form.methodName"></el-input>
                    </el-form-item></el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="显示顺序" prop="itemIndex">
                        <el-input-number v-model="form.itemIndex" :min="0" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="是否有状态" prop="isConcurrent">
                        <el-switch v-model="form.isConcurrent" size="large" inline-prompt :active-icon="Check"
                            :inactive-icon="Close" active-value="1" inactive-value="0" />
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="启动后运行" prop="startupAfterRun">
                        <el-switch v-model="form.startupAfterRun" size="large" inline-prompt :active-icon="Check"
                            :inactive-icon="Close" active-value="1" inactive-value="0" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="保存日志" prop="saveTaskLog">
                        <el-switch v-model="form.saveTaskLog" size="large" inline-prompt :active-icon="Check"
                            :inactive-icon="Close" active-value="1" inactive-value="0" />
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="输出控制台" prop="printConsole">
                        <el-switch v-model="form.printConsole" size="large" inline-prompt :active-icon="Check"
                            :inactive-icon="Close" active-value="1" inactive-value="0" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark"></el-input>
                    </el-form-item>

                </el-col>
            </el-row>
        </el-form>
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button type="primary" @click="addQuartz(formRef)">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref } from 'vue';
import { ElNotification } from 'element-plus';
import { FullScreen, CopyDocument, Check, Close } from '@element-plus/icons-vue'
import Api from '@/api/model/system'
const emit = defineEmits(['updatetable'])

const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})


// 添加用户数据的对象
const form = reactive({
    jobName: '',
    jobGroup: '',
    cronExpression: '',
    springId: '',
    methodName: '',
    itemIndex: '',
    isConcurrent: '0',
    startupAfterRun: '0',
    saveTaskLog: '0',
    printConsole: '0',
    remark: ''
});

const formRef = ref()
const formRules = reactive({
})


const updateVisible = () => {
    emit('updatetable')
}



const restAddFormData = () => {
    formRef.value.resetFields();
}



// 上传
const addQuartz = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            addQuartzData();
        }
    })
}

const addQuartzData = async () => {
    var params = {
        bean: form,
    }
    var res = await Api.quartz.save.post(params);
    if (res.code == 200) {
        restAddFormData();
        ElNotification.success({ title: '', message: '添加成功！', duration: 2000 });
        emit('updatetable', true);
    }
}

</script>

<style lang="scss" scoped></style>

